﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace QLTTTH.Config
{
    class DAOBase
    {
        public DAOBase()
        {
 
        }

        public DataSet Select(String sql)
        {
            SqlConnection conn = null;
            try
            {
                conn = Config.getConnection();
                conn.Open();
                SqlDataAdapter dataApdapter = new SqlDataAdapter(sql, conn);
                DataSet dataSet = new DataSet();
                dataApdapter.Fill(dataSet);
                return dataSet;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally {
                conn.Close();
            }
        }

        public bool Update(String sql)
        {
            SqlConnection conn = null;
            bool status = false;
            try
            {
                conn = Config.getConnection();
                conn.Open();
                SqlCommand command = new SqlCommand(sql, conn);
                if (command.ExecuteNonQuery() != 0)
                    status = true;
            }
            catch (Exception ex)
            {
                return false;
            }
            finally
            {
                conn.Close();
            }
            return status;
        }
    }
}
